package shuashuami.hb.com.http;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import shuashuami.hb.com.manager.HbAppManager;

/**
 * <b>类   名：</b>${TYPE_NAME} <br/>
 * <b>类描述：</b> <br/>
 * <b>创建人：</b>zhangqi<br/>
 * <b>创建时间：</b>2017/6/28<br/>
 * <b>修改人：</b>zhangqi<br/>
 * <b>修改时间：</b>2017/6/28<br/>
 * <b>修改备注：</b><br/>
 *
 * @version 1.0.0<br/>
 */
public class HttpCMethods {


    //获取平台
    public static void getPlatform(final HttpOnNextListener listener) {
        int type = HbAppManager.getInstance().getTypeValue();
        HttpUtils.doGet(CURLs.cPlatformUrl, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    if (response.code() == 200) {
                        listener.onNext(response.body().string());
                    }
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //获取平台
    public static void getHomePage(final HttpOnNextListener listener) {
        int type = HbAppManager.getInstance().getTypeValue();
        HttpUtils.doGet(CURLs.cHomePage, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    if (response.code() == 200) {
                        listener.onNext(response.body().string());
                    }
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //获取任务列表
    public static void getChallList(final HttpOnNextListener listener, int page, int size, String platform, String sort, String is_vip) {
        Map<String, String> map = new HashMap<>();
        map.put("page", page + "");
        map.put("size", size + "");
        map.put("platform", platform);
        map.put("sort", sort);
        map.put("is_vip", is_vip);

        HttpUtils.doPost(CURLs.cHall, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //领取任务
    public static void recieveTask(final HttpOnNextListener listener, String brachid, String taskid) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brachid + "");
        map.put("task_id", taskid + "");

        HttpUtils.doPost(CURLs.cRecieveTask, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getUnreadterTask(final HttpOnNextListener listener, String brachid, String status,
                                        String page, String size,String keyword) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brachid + "");
        map.put("status", status);
        map.put("page", page);
        map.put("size", size);
        map.put("keyword",keyword);


        HttpUtils.doPost(CURLs.cuntreated_task, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //任务详情
    public static void getHallInfo(final HttpOnNextListener listener, String brachid, String taskId) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brachid);
        map.put("task_id", taskId);

        HttpUtils.doPost(CURLs.taskInfoWaitSubmit, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //公告详情
    public static void getNoticeInfo(final HttpOnNextListener listener, String notice_id) {
        Map<String, String> map = new HashMap<>();
        map.put("notice_id", notice_id);

        HttpUtils.doPost(CURLs.noticeContentUrl, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //经验值
    public static void getExpLog(final HttpOnNextListener listener, String brachid, String page, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brachid);
        map.put("page", page);
        map.put("size", size);


        HttpUtils.doPost(CURLs.expLog, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //编辑用户信息
    public static void userEdit(final HttpOnNextListener listener, String brsuhId, String type, String data) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);
        map.put("type", type);
        map.put("data", data);


        HttpUtils.doPost(CURLs.userEdit, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //修改密码
    public static void changePassword(final HttpOnNextListener listener, String brsuhId, String oldpwd, String pwd, String repwd) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);
        map.put("oldpwd", oldpwd);
        map.put("pwd", pwd);
        map.put("repwd", repwd);

        HttpUtils.doPost(CURLs.changePassword, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getAgreement(final HttpOnNextListener listener) {
        int type = HbAppManager.getInstance().getTypeValue();
        HttpUtils.doGet(CURLs.adreement, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    if (response.code() == 200) {
                        listener.onNext(response.body().string());
                    }
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getYuE(final HttpOnNextListener listener, String brsuhId) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);

        HttpUtils.doPost(CURLs.getYuE, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void saveZhifubao(final HttpOnNextListener listener, String brsuhId, String name, String num) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);
        map.put("alipay_realname", name);
        map.put("alipay_account", num);

        HttpUtils.doPost(CURLs.saveZhifubao, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getZhifubao(final HttpOnNextListener listener, String brsuhId) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);

        HttpUtils.doPost(CURLs.getZhifubao, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void saveYinhangka(final HttpOnNextListener listener, String brsuhId, String bankcard_name, String bankcard_identify
            , String bankcard_no, String bank_id, String bankcard_address, String bankcard_info) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);
        map.put("bankcard_name", bankcard_name);
        map.put("bankcard_identify", bankcard_identify);
        map.put("bankcard_no", bankcard_no);
        map.put("bank_id", bank_id);
        map.put("bankcard_address", bankcard_address);
        map.put("bankcard_info", bankcard_info);

        HttpUtils.doPost(CURLs.saveYInhangka, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getBankList(final HttpOnNextListener listener) {

        HttpUtils.doGet(CURLs.getYInhangka, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getBank(final HttpOnNextListener listener, String brsuhId) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);

        HttpUtils.doPost(CURLs.getYInhangkaInfo, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void tixian(final HttpOnNextListener listener, String brsuhId, String money, String type) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);
        map.put("money", money);
        map.put("type", type);

        HttpUtils.doPost(CURLs.tixian, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getYongJinmingxi(final HttpOnNextListener listener, String brsuhId, String page, String type, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);
        map.put("page", page);
        map.put("type", type);
        map.put("size", size);

        HttpUtils.doPost(CURLs.yongjinmingxi, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getJilu(final HttpOnNextListener listener, String brsuhId, String page, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);
        map.put("page", page);
        map.put("size", size);

        HttpUtils.doPost(CURLs.jilu, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }


    public static void getWeitongguo(final HttpOnNextListener listener, String brsuhId, String task_id) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);
        map.put("task_id", task_id);

        HttpUtils.doPost(CURLs.weitongguo, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getDaishouhuo(final HttpOnNextListener listener, String brsuhId, String task_id) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);
        map.put("task_id", task_id);

        HttpUtils.doPost(CURLs.weitongguo, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void querenShouhuo(final HttpOnNextListener listener, String brsuhId, String task_id) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);
        map.put("task_id", task_id);
        map.put("comment_images[]", task_id);

        HttpUtils.doPost(CURLs.querenshouhuo, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void recommendApply(final HttpOnNextListener listener, String brsuhId, String id, String content) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brsuhId);
        map.put("recommend_id", id);
        map.put("content", content);

        HttpUtils.doPost(CURLs.recommendApply, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getComplaintList(final HttpOnNextListener listener, String brachid, String page, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brachid + "");
        map.put("page", page);
        map.put("size", size);


        HttpUtils.doPost(CURLs.complainList, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }
}
